
App.controller('testController', ['$rootScope', '$scope', '$state', 'Page', function($rootScope, $scope, $state, Page) {

    //scope 为false true {}
    $scope.parentName = "parent";


    $scope.name = "mark";
    $scope.sexy = "male";
    $scope.age = "30";
    $scope.say = function (str) {
        console.log(str)
    };

    $scope.submit = function() {
        if($scope.signupFrm.$valid) {
            console.log($scope);
        }

    }
}]);

//false：共享作用域
//App.directive('childA', function () {
//    return {
//        restrict: 'E',
//        scope: false,
//        template: function (elem, attr) {
//            return "false:" + document.getElementById('t1').innerHTML;
//        }
//    };
//});
//
////true：继承父域，并建立独立作用域
//App.directive('childB', function () {
//    return {
//        restrict: 'E',
//        scope: true,
//        template: function (elem, attr) {
//            return "true:" + document.getElementById('t1').innerHTML;
//        },
//        controller: function ($scope) {
//            $scope.parentName = "123132";
//            //已声明的情况下，$scope.$watch监听的是自己的parentName
//            $scope.$watch('parentName', function (n, o) {
//                console.log("true : child watch : " + n);
//            });
//
//            //$scope.$parent.$watch监听的是父域的parentName
//            $scope.$parent.$watch('parentName', function (n, o) {
//                console.log("true : parent watch : " + n);
//            });
//        }
//    };
//});
//
////{}：不继承父域，建立独立作用域
//App.directive('childC', function () {
//    return {
//        restrict: 'E',
//        scope: {},
//        template: function (elem, attr) {
//            return "{}:" + document.getElementById('t1').innerHTML;
//        },
//        controller: function ($scope) {
//            $scope.$watch('parentName', function (n, o) {
//                console.log($scope);
//            });
//
//        }
//    };
//});

App.directive('childC', function () {
    return {
        restrict: 'E',
        scope: {
            myName: '=',
            mySexy: '=',
            myAge: '@',
            onSay: '&'
        },
        template: function (elem, attr) {
            return "{}:" + document.getElementById('t1').innerHTML;
        },
        controller: function ($scope) {
            console.log($scope.myName);
            console.log($scope.mySexy);
            console.log($scope.myAge);
            $scope.onSay();
        }
    };
});



